<template>
	<view class="container">
		<view class="navbar">
			<view 
				v-for="(item, index) in navList" :key="index" 
				class="nav-item" 
				:class="{current: tabCurrentIndex === index}"
				@click="tabClick(index)"
			>
				{{item.text}}
			</view>
		</view>
		
		<swiper class="swiper-Demo" :current="tabCurrentIndex" duration="300"   @change="changeTab">
			<swiper-item class="all-top" >
				<scroll-view 
					class="list-scroll-content" 
					scroll-y 
					@scrolltolower="add"
				>
				<!-- 商品介绍 -->
				<view class="all" v-if="tabCurrentIndex==0" v-model="tabCurrentIndex">
					<view class="carousel">
						<swiper class="swiper" indicator-dots circular=true duration="400">
							<swiper-item class="swiper-item" v-for="(item,index) in specList1.IMAGES" :key="index">
								<view class="image-wrapper">
									<image
										:src="img+item"
										class="loaded" 
										mode="aspectFill"
										@tap="previewImagess(img+item)"
										
									></image>
								</view>
							</swiper-item>
						</swiper>
					</view>
					
					<view class="introduce-section" v-for="(item,index) in specSelecteds" :key="index">
						
						<!-- <view class="title" >{{specList1.NAME}}</view> -->
						<view class="un-title">
							<text>{{specList1.NAME}}</text>
						<view class="price-box">
							<text class="price-tip">¥</text>
							<text class="price">{{item.SALEPRICE}}</text>
							<text class="m-price">¥{{specList1.SELLPRICE}}</text>
							<!-- <text class="coupon-tip">{{parseInt(specList1.SELLERPRICE*10/specList1.MARKETPRICE)}}折</text> -->
						</view>
						</view>
						<view class="bot-row">
							<text>销量: {{specList1.SALECOUNT}}</text>
							<text>库存: {{item.SALESTOCK}}</text>
							<text>关注量: {{specList1.COLLECTEDCOUNT}}</text>
							<text>浏览量: {{specList1.BROWSE}}</text>
						</view>
					</view>
					
					<!--  分享 -->
					<!-- <view class="share-section" @click="share">
						<view class="share-icon">
							<text class="yticon icon-xingxing"></text>
							 返
						</view>
						<text class="tit">该商品分享可领49减10红包</text>
						<text class="yticon icon-bangzhu1"></text>
						<view class="share-btn">
							立即分享
							<text class="yticon icon-you"></text>
						</view>
						
					</view> -->
					
					<view class="c-list">
						<view class="c-row b-b" @click="toggleSpec">
							<text class="tit">购买类型</text>
							<view class="con">
								<text class="selected-text" v-for="(sItem, sIndex) in specSelecteds" :key="sIndex">
									{{sItem.TITLE}}
								</text>
							</view>
							<text class="yticon icon-you"></text>
						</view>
						<view class="c-row b-b" @click="toggleSpec1">
							<text class="tit">商品参数</text>
							<view class="con">
								<text class="selected-text" >
									点击查看
								</text>
							</view>
							<text class="yticon icon-you"></text>
						</view>
						<!-- <view class="c-row b-b">
							<text class="tit">优惠券</text>
							<text class="con t-r red">领取优惠券</text>
							<text class="yticon icon-you"></text>
						</view> -->
						<view class="c-row b-b">
							<text class="tit">促销活动</text>
							<view class="con-list">
								<text>{{specList1.SHORTINFO}}</text>
							</view>
						</view>
						<!-- <view class="c-row b-b">
							<text class="tit">服务</text>
							<view class="bz-list con">
								<text>7天无理由退换货 ·</text>
								<text>假一赔十 ·</text>
							</view>
						</view> -->
					</view>
					<!-- 评价 -->
					<view class="eva-section" v-if="comment != 0 ">
						<view class="e-header">
							<text class="tit">评价</text>
							<text>({{commentsize}})</text>
							<!-- <text class="tip">更多</text> -->
							<text class="yticon icon-you"></text>
						</view> 
						<view class="eva-box">
							<image class="portrait" :src="comment.IMG==null ? '/static/missing-face.png' : img+comment.IMG " mode="aspectFill"></image>
							<view class="right">
								<text class="name" >{{comment.NAME}}</text>
								<text class="time">{{comment.CREATEDATE}}</text>
								<text class="con">{{comment.CONTENT}}</text>
								<view class="bot">
									<view class="attr">购买类型：{{comment.TITLE}}</view>
								</view>
								<view class="commimg">
									<view class=""  v-for="(Item, Index) in commentimg" :key="Index">
											<image @click="previewImage(Index)" class="image" :src="img+Item" style=""  mode="aspectFill"  ></image>
									</view>
								</view>
							</view>
						</view>
					</view>
					
					<!-- 新鲜好物 -->
					
					<view class="new-section m-t">
						<view class="s-header m-t" >
							<view class="tit-box" >
								<text class="tit">同类推荐</text>
							</view>
						</view>
						<scroll-view class="floor-list" scroll-x>
							<view v-if="!otherGoods||otherGoods.length==0" style="text-align: center;font-size: 25upx;color: dimgray;">暂无推荐</view>
							<view v-else class="scoll-wrapper">
								<view 
									v-for="(item, index) in otherGoods" :key="index"
									class="floor-item"
									@click="navToDetailPage(item)"
								>
									<view >
										<view class="un-huangtuoyuan">
											<text > 新品</text>
										</view>
										<image :src="img+ item.THUMB" mode="aspectFill"></image>
									</view>
									
									<text class="title clamp">{{item.NAME}}</text>
									<text class="tit2 title2 clamp">{{item.SHORTINFO}}</text>
									<text class="price">￥{{item.PRICE1}}</text>
								</view>
								<view class="more" @click="navToNewproductPage()">
									<text>查看全部</text>
									<text>More+</text>
								</view>
							</view>
							
						</scroll-view>
						
					</view>
					
					
				<!-- 商品参数-模态层弹窗 -->
				<view 
					class="popup spec" 
					:class="specClass1"
					@touchmove.stop.prevent="stopPrevent"
					@click="toggleSpec1"
				>
					<!-- 遮罩层 -->
					<view class="mask"></view>
					<view class="layer attr-content" @click.stop="stopPrevent" style="height: 80%;padding-bottom: 200upx;">
						<view class="top">商品参数</view>
						<scroll-view  scroll-y style="height: 100%;">
							<view v-if="!brandList||brandList.length==0" style="color: #909399;text-align: center;width: 100%;height: 500upx;line-height: 500upx;font-size: 32upx;"> 暂无参数</view>
							<view v-else v-for="(item,index) in brandList" :key="index" class="brand-list">
								<view  class="item-list">
									<view class="text1"><text >{{item.INAME}}</text></view>
									<view class="text"><text >:</text></view>
									<view class="text2"><text >{{item.IDETAIL}}</text></view>
								</view>
							</view>
						</scroll-view>
						
						<button class="btn" @click="toggleSpec1">确定</button>
					</view>
				</view>
					
					
					<!-- 规格-模态层弹窗 -->
					<view 
						class="popup spec" 
						:class="specClass"
						@touchmove.stop.prevent="stopPrevent"
						@click="toggleSpec"
					>
						<!-- 遮罩层 -->
						<view class="mask"></view>
						<view class="layer attr-content" @click.stop="stopPrevent" style="height: 70%;" :style="{padding:specLists?'0upx 0upx 400upx':'0upx 0upx 200upx' }">
							<view class="a-t"  >
								<!-- <image src="https://gd3.alicdn.com/imgextra/i3/0/O1CN01IiyFQI1UGShoFKt1O_!!0-item_pic.jpg_400x400.jpg"></image> -->
								<view class="right" v-for="(sItem, sIndex) in specSelecteds" :key="sIndex">
									<text class="price">¥{{sItem.SALEPRICE}}</text>
									<text class="stock">库存：{{sItem.SALESTOCK}}件</text>
									<view class="selected">
										已选：
										<text class="selected-text" >
											{{sItem.TITLE}}
										</text>
									</view>
								</view>
							</view>
							<scroll-view  scroll-y style="height: 100%;">
							<view v-if="!specLists" style="color: #CCCCCC;text-align: center;width: 100%;height: 500upx;line-height: 500upx;font-size: 32upx;"> 暂无参数</view>

							<view v-else v-for="(item,indexs) in specLists" :key="indexs" class="attr-list">
								
								<view class="item-list">
									<text 
									class="tit"
									
									:class="{selected: item.selected}"
									@click="selectSpec(indexs, item.ID)"
									>{{item.TITLE}}</text>
									<!-- <text 
										v-for="(childItem, childIndex) in specChildList" 
										v-if="childItem.pid === item.id"
										:key="childIndex" class="tit"
										:class="{selected: childItem.selected}"
										@click="selectSpec(childIndex, childItem.pid)"
									>
										{{childItem.name}}
									</text> -->
								</view>
							</view>
							</scroll-view>
							<view class="layer-mid">
								<text class="text">购买数量:</text>
								<uni-number-box  class="number-box"  :value="num" @change="change" />
							</view>
							
							<!-- <button class="btn" @click="toggleSpec">完成</button> -->
						</view>
					</view>
					
					
					
					
					<uni-popup  :show="showQr=='show'" type="middle" >
						
						<view class="popups">
							<view class="">扫码联系客服</view>
							<image  :src="img+specList1.QRTHUMB"  class="popupimg"></image>
							<view class="yticon icon-fork badge" @click="showQrs"></view>
						</view>
						
					</uni-popup>
					
					
				</view>
				
				
				<!-- 图片详情 -->
				<view class="all" v-if="res!= undefined || res.length == 0" >
					<view class="top">
						<view class="detail-desc">
							<view class="d-header">
								<text>图文详情</text>
							</view>
							<view style="width:100%" v-for="(item, index) in res" :key="index" >
								<img style="width:100%;display:block;" :src="img+res[index]" @tap="previewImagess(img+res[index])" />
							</view>
						</view>
					</view>
				</view>
				
				</scroll-view>
			</swiper-item>
			
			<swiper-item class="all-top"  >
				<scroll-view 
					class="list-scroll-content" 
					scroll-y 
				>
				<uni-popup  :show="showQr=='show'" type="middle" >
					
					<view class="popups">
						<view class="">扫码联系客服</view>
						<image  :src="img+specList1.QRTHUMB"  class="popupimg"></image>
						<view class="yticon icon-fork badge" @click="showQrs"></view>
					</view>
					
				</uni-popup>
				<!-- 图片详情 -->
				<view class="all" v-if="tabCurrentIndex==1" v-model="tabCurrentIndex">
					<view class="top">
						<view class="detail-desc">
							<view class="d-header">
								<text>图文详情</text>
							</view>
							<view style="width:100%" v-for="(item, index) in res" :key="index" >
								<img style="width:100%;display:block;" :src="img+res[index]" @tap="previewImagess(img+res[index])" />
							</view>
							<!-- <rich-text :nodes="desc"></rich-text> -->
						</view>
						<!-- <button class="button" type="primary"  @click="share">分享有惊喜</button>
						<view class="texts">
							<view class="text">每件商品每天首次分享即可参加抽奖</view>
							<view class="text">最高100元优惠券</view>
							<view class="text">(分享后，返回亿拼惠才能抽奖哦)</view>
						</view> -->
					</view>
					<!-- <view class="buttom">
						<view class="top">注意事项</view>
						<view class="mid">
							<view class="tittle">• 购买运费如何收取？</view>
							<text class="text">单笔订单金额(不含运费)满88元免邮费；不满88元，每单收取10元运费。（港澳台地区需满500元免邮费；不满500元，每单收取30元运费)</text></view>
						<view class="mid">
							<view class="tittle">• 使用什么快递发货?</view>
							<text class="text">默认使用顺丰快递发货(个别商品使用其他快递）</text>
							<text class="text">配送范围覆盖全国大部分地区(港澳台地区除外）。</text>
						</view>
						<view class="mid">
							<view class="tittle">• 如何申请退货?</view>
							<text class="text">1.自收到商品之日起30日内，顾客可申请无忧退货，退款将原路返还，不同的银行处理时间不同，预计1-5个工作日到账；</text>
							<text class="text">2.内裤和食品等特殊商品无质量问题不支持退货；</text>
							<text class="text">3.退货流程：</text>
							<text class="text">确认收货-申请退货-客服审核通过-用户寄回商品-仓库签收验货-退款审核-退款完成；</text>
							<text class="text">4.因亿拼惠产生的退货，如质量问题，退货邮费由亿拼惠承担，退款完成后会以现金券的形式报销。因客户个人原因产生的退货，购买和寄回运费由客户个人承担。</text>
						</view>
					</view> -->
				</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		
		
		
		<!-- 分享 -->
		<!-- <share 
			ref="share" 
			:contentHeight="580"
			:shareList="shareList"
		></share> -->
			<!-- 底部操作菜单 -->
		<view class="page-bottom">
			<navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn">
				<text class="yticon icon-xiatubiao--copy"></text>
				<text>首页</text>
			</navigator>
			<view class="p-b-btn" @click="showQrs">
				<text class="yticon icon-icon--" ></text>
				<text>客服</text>
			</view>
			<view class="p-b-btn" :class="{active: favorite}" @click="toFavorite">
				<text class="yticon icon-shoucang"></text>
				<text>收藏</text>
			</view>
			
			<view class="action-btn-group">
				<button type="primary" class=" action-btn no-border buy-now-btn" @click="buy">立即购买</button>
				<button type="primary" class=" action-btn no-border add-cart-btn" @click="saveCard(num,selectedid)">加入购物车</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {  
	    mapMutations  
	} from 'vuex';
	import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue'
	import share from '@/components/share'
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	export default{
		components: {
			share,
			uniNumberBox,
			uniPopup,
		},
		data() {
			return {
				num : 1,
				id : '',
				SIGNATURE: '',
				tabCurrentIndex: 0,
				navList: [{
						state: 0,
						text: '商品介绍',
						loadingType: 'more',
						commentList: [],
					},
					{
						state: 1,
						text: '图文详情',
						loadingType: 'more',
						commentList: [],
					},
					
				],
				specClass1: 'none',
				specClass: 'none',
				specSelected:[],
				specSelected1:[],
				specSelecteds:[],
				favorite: false,
				shareList: [],
				
				
				specList1: '',
				specLists: [],
				brandList: [],
				
				goodsList: [],
				otherGoods:[],
				ZSACTIVITY: '',
				ZSCOUPONNUM: '',
				ZSDEDUNUM: '',
				ZSPOINTNUM: '',
				time:0,
				img:'',
				res: '',
				selectedid: '',//选中商品的ID
				comment:'',
				commentsize:'',
				commentimg:'',
				showQr:'none',
				count:0,
				indexScrolly:0,
				scrollY:0
			};
		},
		async onLoad(options){
			this.id = options.id;
			this.loadData(this.id);
			this.loadComm(this.id);
			this.img = getApp().globalData.imageAddress;
		
			
			this.shareList = await this.$api.json('shareList');
			this.goodsList = await this.$api.json('goodsList');
			
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods:{
			//swiper 切换
			changeTab(e){
				this.tabCurrentIndex = e.target.current;
				this.loadData(this.id);
			},
			add(){
				this.$http.post("/goods/detailDescribe",{
					SIGNATURE : this.SIGNATURE,
					GOODSID : this.id,
				}).then((res) => {
					this.res = res.data.OBJECT.DESCRIBE;
					
				}).catch((err)=>{
					console.log('request fail', err);
				})
			},
			/**
			 * 预览图片
			 */
			previewImagess(e) {
				var lsi = []
				lsi[0] = e
				uni.previewImage({
					current: e,
					urls: lsi
				})
			},
			showQrs() {
				console.log(this.showQr);
				if(this.showQr === 'show'){
					this.showQr = 'hide';
					setTimeout(() => {
						this.showQr = 'none';
					}, 250);
				}else if(this.showQr === 'none'){
					this.showQr = 'show';
				}
			},
			change(value) {
				this.num = value
			},
			//预览图片
			previewImage(e) {
				var current = e
				var list = this.commentimg.map(item=>{
					return item = this.img+ item
				})
				uni.previewImage({
					current: current,
					urls: list
				})
			},
			//缓存,加入购物车
			saveCard(num,selectedid){
				// this.$http.post("/user/info",{
				// 	SIGNATURE : uni.getStorageSync("SIGNATURE"),
				// 	TOKEN: uni.getStorageSync('userInfo').TOKEN,
				// }).then((res) => {
				// 	if(res.data.STATE == '903'||res.data.STATE == '904'){
				// 		uni.navigateTo({
				// 			url:'/pages/public/login1'
				// 		})
				// 	}
				// }).catch((err)=>{
				// 	console.log('request fail', err);
				// })
				let newcard = {selectedid:selectedid,num: num}
				let key = uni.getStorageSync('userInfo').USER == undefined ?  'card' :  uni.getStorageSync('userInfo').USER.PHONE
				let car = uni.getStorageSync(key)|| []
				if(car.length==0){
					car.push(newcard);
				}else{
					let len = 0
					car.forEach(item=>{
						if(item.selectedid == selectedid){
							item.num = num
							len ++
						}
					})
					if(len == 0){
						car.push(newcard)
					}
				}
				uni.setStorage({
					key:key,
					data: car
				});
				uni.showToast({
					duration:500,
					icon:"success",
					title:"成功加入购物车"
				})
				console.log("9999999",uni.getStorageSync(key));
			},
			//加载评价
			async loadComm(id){
				this.$http.post("/goods/commentlist",{
					SIGNATURE : this.SIGNATURE,
					ID : id,
					ISONE: 1,
					ISEXCHANGE: 0
				}).then((res) => {
					console.log("评价",res.data.OBJECT);
					
					if(res.data.OBJECT == ''){
						this.comment = res.data.OBJECT;
					}else{
						this.comment = res.data.OBJECT.LIST
					}
					
					this.commentsize = res.data.OBJECT.SIZE
					this.commentimg = res.data.OBJECT.IMAGES
				}).catch((err)=>{
					console.log('request fail', err);
				})
			},
			//请求数据
			async loadData(id){
				this.SIGNATURE = uni.getStorageSync("SIGNATURE");
				if(this.tabCurrentIndex === 0){
					this.$http.post("/goods/detail",{
						SIGNATURE : this.SIGNATURE,
						GOODSID : id,
						ISLOOK: 1,
					}).then((res) => {
						console.log("ressssssssssssssssssss",res.data.OBJECT);
						if ( res.data.STATE==='-1' && res.statusCode===200 && res.data.MSG === '商品不存在'){
							uni.showModal({
								title:'该商品已下架',
								success:function(){
									uni.switchTab({
										url:'/pages/index/index'
									})
								}
							})
						}
						else if(res.data.STATE==='0' && res.statusCode===200){
							this.specList1 = res.data.OBJECT;
							this.specLists = res.data.OBJECT.SPEC;
							this.brandList = res.data.OBJECT.COMSPEC;
							this.specLists = this.specLists.map(item=>{
								
								if (this.specSelecteds.length == 0 ){
									item.selected = true
									this.selectedid = item.ID
									this.specSelecteds.push(item)
								}else{
									item.selected = false
								}
								return item
							})
							console.log("*********",this.specLists)
							this.ZSACTIVITY = res.data.OBJECT.ZSACTIVITY;
							this.ZSCOUPONNUM = res.data.OBJECT.ZSCOUPONNUM;
							this.ZSDEDUNUM = res.data.OBJECT.ZSDEDUNUM;
							this.ZSPOINTNUM = res.data.OBJECT.ZSPOINTNUM;
							uni.setStorageSync("ZSACTIVITY",this.ZSACTIVITY);
							uni.setStorageSync("ZSCOUPONNUM",this.ZSCOUPONNUM);
							uni.setStorageSync("ZSDEDUNUM",this.ZSDEDUNUM);
							uni.setStorageSync("ZSPOINTNUM",this.ZSPOINTNUM);
						}else{
							uni.showToast({
								title:'网络异常，请稍后重试',
								icon :'none'
							})
							
						}
						
					}).catch((err)=>{
						console.log('request fail', err);
					})
					this.$http.post("/goods/findOtherGoodsSamecate",{
						SIGNATURE : this.SIGNATURE,
						GOODSID : id,
						PAGE:1,
					}).then((res) => {
						this.otherGoods=res.data.OBJECT;
					}).catch((err)=>{
						console.log('request fail', err);
					})
					
				}else {
					this.$http.post("/goods/detailDescribe",{
						SIGNATURE : this.SIGNATURE,
						GOODSID : id,
					}).then((res) => {
						this.res = res.data.OBJECT.DESCRIBE;
						
					}).catch((err)=>{
						console.log('request fail', err);
					})
				}
				this.$http.post("/user/collectionList1",{
					SIGNATURE:uni.getStorageSync("SIGNATURE"),
					TOKEN:uni.getStorageSync('userInfo').TOKEN,
					GOODSID:this.id,
				}).then(res=>{
					if(res.data.STATE==='0' && res.statusCode===200){
						if(res.data.OBJECT[0]&&res.data.OBJECT[0].ISCANCEL==0){
							this.favorite=true;
						}
					}
				}).catch(err=>{
					console.log('request fail',err);
				})
				//添加商品浏览记录
				this.$http.post("/user/addHistory",{
					SIGNATURE:uni.getStorageSync("SIGNATURE"),
					TOKEN:uni.getStorageSync('userInfo').TOKEN,
					GOODSID:this.id,
					TYPE:1,
				}).then(res=>{
					if(res.data.STATE==='0' && res.statusCode===200){
						console.log("浏览记录已添加")
					}
				}).catch(err=>{
					console.log('request fail',err);
				})
				
			},
			
			
			//顶部tab点击
			tabClick(index){
				console.log(index);
				this.tabCurrentIndex = index;
			},
			//规格弹窗开关
			toggleSpec1() {
				if(this.specClass1 === 'show'){
					this.specClass1 = 'hide';
					setTimeout(() => {
						this.specClass1 = 'none';
					}, 250);
				}else if(this.specClass1 === 'none'){
					this.specClass1 = 'show';
				}
			},
			
			//规格弹窗开关
			toggleSpec() {
				if(this.specClass === 'show'){
					this.specClass = 'hide';
					setTimeout(() => {
						this.specClass = 'none';
					}, 250);
				}else if(this.specClass === 'none'){
					this.specClass = 'show';
				}
			},
			//选择规格
			selectSpec(index, pid){
				this.selectedid = pid
				//状态都改为未选中
				this.specLists = this.specLists.map(item=>{ 
					item.selected = false 
					return item
				})
				//点击的规格，状态变为选中
				this.specLists[index].selected = true
				//清空选中框
				this.specSelecteds = []; 
				//把新true 加进去
				this.specLists.forEach(item=>{ 
					if(item.selected === true){ 
						this.specSelecteds.push(item); 
					} 
				})
				
			},
			// selectSpec(index, pid){
			// 	let list = this.specChildList;
			// 	list.forEach(item=>{
			// 		if(item.pid === pid){
			// 			this.$set(item, 'selected', false);
			// 		}
			// 	})
			// 
			// 	this.$set(list[index], 'selected', true);
			// 	//存储已选择
			// 	/**
			// 	 * 修复选择规格存储错误
			// 	 * 将这几行代码替换即可
			// 	 * 选择的规格存放在specSelected中
			// 	 */
			// 	this.specSelected = []; 
			// 	list.forEach(item=>{ 
			// 		if(item.selected === true){ 
			// 			this.specSelected.push(item); 
			// 		} 
			// 	})
			// 	
			// },
			//同类推荐页面
			navToNewproductPage(){
				this.$http.post("/goods/queryGoodsCate",{
					SIGNATURE : this.SIGNATURE,
					GOODSID : this.id,
				}).then((res) => {
					uni.navigateTo({
						url: '/pages/product/list?fid='+res.data.OBJECT.CATEGORYONID+'&sid='+res.data.OBJECT.CATEGORYTWID+'&tid='+res.data.OBJECT.CATEGORYTHID
					})
				}).catch((err)=>{
					console.log('request fail', err);
				})
			},
			//商品详情页
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				console.log("/////////",item)
				let id = item.ID;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			//分享
			share(){
				this.$refs.share.toggleMask();	
			},
			//收藏
			toFavorite(){
				this.$http.post("/user/setCollect",{
					 SIGNATURE : uni.getStorageSync("SIGNATURE"),
					 TOKEN: uni.getStorageSync('userInfo').TOKEN,
					 FAV:this.favorite,
					 GOODSID:this.id,
				}).then(res=>{
					if(res.data.STATE == '903'||res.data.STATE == '904'||res.data.STATE == '905'||res.data.STATE == '906'||res.data.STATE == '907'){
						// #ifndef MP-WEIXIN
						uni.navigateTo({
							url:'/pages/public/login1'
						})
						// #endif
						// #ifdef MP-WEIXIN
						uni.showToast({
							title:"请登录",
							icon:"none"
						})
						// #endif
						
					}
					if(res.data.STATE==='0' && res.statusCode===200){
						this.favorite = !this.favorite;
						if(this.favorite==true){
							uni.showToast({
								title:"收藏成功",
								icon:"none"
							})
						}else{
							uni.showToast({
								title:"取消收藏成功",
								icon:"none"
							})
						}
					}
				}).catch(err =>{
				 console.log('request fail', err);
				})
			},
			buy(){
				
				if(this.specSelecteds[0].SALESTOCK < this.num){
					uni.showToast({
						title:"库存不足",
						icon:"none"
					})
					return;
				}
				console.log("LLLLLLLLLLLLLLLLL",this.specClass)
				if(this.specClass === 'hide' || this.specClass === 'none'){
					this.specClass = 'show';
				}else if(this.specClass === 'show'){
					this.$http.post("/user/info",{
						 SIGNATURE : uni.getStorageSync("SIGNATURE"),
						 TOKEN: uni.getStorageSync('userInfo').TOKEN,
					}).then(res=>{
						if(res.data.STATE == '905'||res.data.STATE == '903'||res.data.STATE == '904'||res.data.STATE === "907"||res.data.STATE === "906"){
							uni.removeStorageSync('userInfo')
							uni.showModal({
								content: '请先登录再购买',
								success: (res)=>{
									if(res.confirm){
										// #ifdef MP-WEIXIN
										uni.switchTab({
											url:"/pages/user/user"
										})
											       
										// #endif
										// #ifndef MP-WEIXIN
										uni.reLaunch({
											url:'/pages/public/login1'
										})
										// #endif
										
									}else if(res.cancel) {
										
									}
								},
							})
						}else if(res.data.STATE==='0' && res.statusCode===200){
							uni.navigateTo({
								url: `/pages/order/createOrder?id=`+this.id+"&num="+this.num+"&SID="+this.selectedid
							})
						}
					}).catch(err =>{
					 console.log('request fail', err);
					})
				}
				
				
			},
			stopPrevent(){}
		},
		
		// #ifndef MP
		
		//点击导航栏 buttons 时触发
		onNavigationBarButtonTap(e) {
			this.$refs.share.toggleMask();	
		}
		// #endif
	}
</script>

<style lang='scss'>
	page, .container{
		background: $page-color-base;
		padding-bottom: 60upx;
		height: 100%;
		.swiper-Demo{
			height: 100%;
			.list-scroll-content{
				height: 100%;
			}
		}
	}
	.popups{
		position: absolute;
		background: #fff;
		width: 450upx;
		height: 500upx;
		font-size:35upx;
		text-align:center;
		padding-top:10upx;
		.popupimg{
			margin-top: 20upx;
			width: 400upx;
			height: 400upx;
			border: 2upx solid #9D9D9D;
		}
		.yticon{
			position: absolute;
			color: #EBEDF0;
			background-color:  #999999;
			top: 10upx;
			left: 410upx;
			border-radius: 50upx;
		}
	}
	.icon-you{
		font-size: $font-base + 2upx;
		color: #888;
	}
	.carousel {
		height: 750upx;
		position:relative;
		
		.swiper{
			height: 100%;
		}
		.image-wrapper{
			/* width: 100vw;
			height: 100vh; */
			width: 100%;
			height: 100%;
		}
		.swiper-item {
			display: flex;
			justify-content: center;
			align-content: center;
			height: 750upx;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
		
	}
	
	/* 标题简介 */
	.introduce-section{
		background: #fff;
		padding: 20upx 30upx;
		
		.title{
			font-size: 32upx;
			color: $font-color-dark;
			height: 50upx;
			line-height: 50upx;
		}
		.un-title{
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			font-size: 32upx;
		}
		.price-box{
			display:flex;
			align-items:baseline;
			height: 64upx;
			padding: 10upx 0;
			font-size: 26upx;
			color:$uni-color-primary;
		}
		.price{
			font-size: $font-lg + 8upx;
			font-weight: 900;
		}
		.m-price{
			margin:0 12upx;
			color: $font-color-light;
			text-decoration: line-through;
		}
		.coupon-tip{
			align-items: center;
			padding: 4upx 10upx;
			background: $uni-color-primary;
			font-size: $font-sm;
			color: #fff;
			border-radius: 6upx;
			line-height: 1;
			transform: translateY(-4upx); 
		}
		.bot-row{
			display:flex;
			align-items:center;
			height: 50upx;
			font-size: $font-sm;
			color: $font-color-light;
			text{
				flex: 1;
			}
		}
	}
	/* 分享 */
	.share-section{
		display:flex;
		align-items:center;
		color: $font-color-base;
		background: linear-gradient(left, #fdf5f6, #fbebf6);
		padding: 12upx 30upx;
		.share-icon{
			display:flex;
			align-items:center;
			width: 70upx;
			height: 30upx;
			line-height: 1;
			border: 1px solid $uni-color-primary;
			border-radius: 4upx;
			position:relative;
			overflow: hidden;
			font-size: 22upx;
			color: $uni-color-primary;
			&:after{
				content: '';
				width: 50upx;
				height: 50upx;
				border-radius: 50%;
				left: -20upx;
				top: -12upx;
				position:absolute;
				background: $uni-color-primary;
			}
		}
		.icon-xingxing{
			position:relative;
			z-index: 1;
			font-size: 24upx;
			margin-left: 2upx;
			margin-right: 10upx;
			color: #fff;
			line-height: 1;
		}
		.tit{
			font-size: $font-base;
			margin-left:10upx;
		}
		.icon-bangzhu1{
			padding: 10upx;
			font-size: 30upx;
			line-height: 1;
		}
		.share-btn{
			flex: 1;
			text-align:right;
			font-size: $font-sm;
			color: $uni-color-primary;
		}
		.icon-you{
			font-size: $font-sm;
			margin-left: 4upx;
			color: $uni-color-primary;
		}
	}
	
	.c-list{
		font-size: $font-sm + 2upx;
		color: $font-color-base;
		background: #fff;
		.c-row{
			display:flex;
			align-items:center;
			padding: 20upx 30upx;
			position:relative;
		}
		.tit{
			width: 140upx;
		}
		.con{
			flex: 1;
			color: $font-color-dark;
			.selected-text{
				margin-right: 10upx;
			}
		}
		.bz-list{
			height: 40upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			text{
				display: inline-block;
				margin-right: 30upx;
			}
		}
		.con-list{
			flex: 1;
			display:flex;
			flex-direction: column;
			color: $font-color-dark;
			line-height: 40upx;
		}
		.red{
			color: $uni-color-primary;
		}
	}
	
	/* 评价 */
	.eva-section{
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		margin-top: 16upx;
		.e-header{
			display: flex;
			align-items: center;
			height: 70upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;
			.tit{
				font-size: $font-base + 2upx;
				color: $font-color-dark;
				margin-right: 4upx;
			}
			.tip{
				flex: 1;
				text-align: right;
			}
			.icon-you{
				margin-left: 10upx;
			}
		}
	}
	.eva-box{
		display: flex;
		padding: 20upx 0;
		.portrait{
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			border-radius: 100px;
		}
		.right{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: $font-base;
			color: $font-color-base;
			padding-left: 26upx;
			
			.con{
				font-size: $font-base;
				color: $font-color-dark;
				padding: 20upx 0;
			}
			.bot{
				display: flex;
				justify-content: space-between;
				font-size: $font-sm;
				color:$font-color-light;
			}
			.commimg{
				display:flex;
				margin-top: 20upx;
				.image{
					margin-right: 20upx;
					width: 150upx;
					height: 150upx;
				}
			}
		}
	}
	
	/*  详情 */
	.detail-desc{
		background: #fff;
		margin: 40upx;
		.d-header{
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80upx;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			position: relative;
				
			text{
				padding: 0 20upx;
				background: #fff;
				position: relative;
				z-index: 1;
			}
			&:after{
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translateX(-50%);
				width: 300upx;
				height: 0;
				content: '';
				border-bottom: 1px solid #ccc; 
			}
		}
	}
	
	/* 规格选择弹窗 */
	.attr-content{
		padding: 10upx 30upx;
		.top{
			text-align: center;
			font-size: 35upx;
			padding: 20upx 0upx;
		}
		.brand-list{
			.item-list{
				padding: 20upx;
				border-top: 1upx solid #E4E7ED;
				display: flex;
				font-size: 28upx;
				.text1{
					width: 200upx;
					color: #808080;
					text-align: right;
				}
				.text{
					margin-left: 10upx;
					color: #909399;
				}
				.text2{
					width: 500upx;
					margin-left: 20upx;
					color: #909399;
				}
			}
			
		}
		.a-t{
			display: flex;
			image{
				width: 170upx;
				height: 170upx;
				flex-shrink: 0;
				margin-top: -40upx;
				border-radius: 8upx;;
			}
			.right{
				display: flex;
				flex-direction: column;
				padding-left: 24upx;
				font-size: $font-sm + 2upx;
				color: $font-color-base;
				line-height: 42upx;
				.price{
					font-size: $font-lg;
					color: $uni-color-primary;
					margin-bottom: 10upx;
				}
				.selected-text{
					margin-right: 10upx;
				}
			}
		}
		.attr-list{
			display: flex;
			flex-direction: column;
			font-size: $font-base + 2upx;
			color: $font-color-base;
			padding-top: 30upx;
			padding-left: 10upx;
		
			.item-list{
				display: flex;
				flex-wrap: wrap;
				text{
					display: flex;
					align-items: center;
					justify-content: center;
					background: #eee;
					margin-right: 40upx;
					border-radius: 10upx;
					min-width: 80upx;
					padding: 15upx 20upx;
					font-size: 24upx;
					color: $font-color-dark;
				}
				.selected{
					background: #fbebee;
					color: $uni-color-primary;
				}
			}
		}
	}
	
	/*  弹出层 */
	.popup {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 99;
		.kit{
			.selected{
				background: #fbebee;
				color: $uni-color-primary;
			}
		}
		&.show {
			display: block;
			.mask{
				animation: showPopup 0.2s linear both;
			}
			.layer {
				animation: showLayer 0.2s linear both;
			}
		}
		&.hide {
			.mask{
				animation: hidePopup 0.2s linear both;
			}
			.layer {
				animation: hideLayer 0.2s linear both;
			}
		}
		&.none {
			display: none;
		}
		.mask{
			position: fixed;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: 1;
			background-color: rgba(0, 0, 0, 0.4);
		}
		.layer {
			position: fixed;
			z-index: 99;
			bottom: 0;
			width: 100%;
			min-height: 40vh;
			border-radius: 10upx 10upx 0 0;
			background-color: #fff;
			.btn{
				height: 66upx;
				line-height: 66upx;
				border-radius: 100upx;
				background: $uni-color-primary;
				font-size: $font-base + 2upx;
				color: #fff;
				margin: 30upx auto 20upx;
			}
			.layer-mid{
				padding: 20upx 0upx;
				display: flex;
				border-top: 1upx solid #f5f5f5;
				border-bottom: 1upx solid #f5f5f5;
				margin-bottom: 10upx;
				.number-box{
					font-size: 20upx;
					text-align: center;
					font-weight: 900;
					height: 60upx;
					width: 220upx;
				}
				.text{
					width: 65%;
					font-size: 35upx;
					padding-top: 10upx;
					padding-left: 10upx;
				}
			}
			
		}
		@keyframes showPopup {
			0% {
				opacity: 0;
			}
			100% {
				opacity: 1;
			}
		}
		@keyframes hidePopup {
			0% {
				opacity: 1;
			}
			100% {
				opacity: 0;
			}
		}
		@keyframes showLayer {
			0% {
				transform: translateY(120%);
			}
			100% {
				transform: translateY(0%);
			}
		}
		@keyframes hideLayer {
			0% {
				transform: translateY(0);
			}
			100% {
				transform: translateY(120%);
			}
		}
	}
	
	/* 底部操作菜单 */
	.page-bottom{
		position:fixed;
		bottom: 0upx;
		z-index: 95;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 750upx;
		height: 100upx;
		background: rgba(255,255,255,.9);
		box-shadow: 0 0 20upx 0 rgba(0,0,0,.5);
		.p-b-btn{
			display:flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: $font-sm;
			color: $font-color-base;
			width: 96upx;
			height: 80upx;
			.yticon{
				font-size: 40upx;
				line-height: 48upx;
				color: $font-color-light;
			}
			&.active, &.active .yticon{
				color: #E02E24;
			}
			
			.icon-shoucang{
				font-size: 46upx;
			}
		}
		.action-btn-group{
			display: flex;
			height: 100upx;
			width: 460upx;
			text-align: center;
			/* border-radius: 100px; */
			overflow: hidden;
			/* box-shadow: 0 20upx 40upx -16upx #E02E24; */
			/* box-shadow: 1px 2px 5px #E02E24; */
			background: #E02E24;
			/* background: linear-gradient(to right, #ffac30,#fa436a,#F56C6C); */
			margin-left: 20upx;
			position:relative;
			/* &:after{
				content: '';
				position:absolute;
				top: 50%;
				right: 50%;
				transform: translateY(-50%);
				height: 28upx;
				width: 0;
				border-right: 1px solid rgba(255,255,255,.5);
			} */
			.action-btn{
				display:flex;
				align-items: center;
				justify-content: center;
				width: 180upx;
				height: 100%;
				font-size: $font-base ;
				padding: 0;
				border-radius: 0;
				background: transparent;
			}
			.add-cart-btn{
				background-color: $base-color;
				width: 240upx;
				height: 100upx;
				margin-left: 40upx;
			}
			.buy-now-btn{
				padding-left: 30upx;
			}
		}
	}
	
	/* 新鲜好物 */
	.new-section{
		margin-top: 20upx;
		padding: 0upx 20upx;
		background: #fff;
		.s-header{
			text-align: center;
			padding: 30upx 0upx;
			.tit-box{
				.tit{
					font-size: $font-sm +6upx;
					color: dimgray;
				}
			}
		}
		.floor-list{
			white-space: nowrap;
		}
		.scoll-wrapper{
			display:flex;
			align-items: flex-start;
		}
		.floor-item{
			width: 220upx;
			margin: 0upx 20upx;
			font-size: $font-sm+2upx;
			text-align: center;
			image{
				margin-top: 15upx;
				margin-bottom: 20upx;
				width: 160upx;
				height: 160upx;
				border-radius: 6upx;
			}
			.price{
				color: $uni-color-primary;
			}
			.tit2{
				font-size: $font-sm;
				color: $font-color-light;
				width: 220upx;
			}
			.title2{
				font-size: 25upx;
				line-height: 40upx;
				width: 220upx;
			}
			.un-huangtuoyuan{
				z-index: 1;
				position: absolute;
				margin-left: 88px;
				width: 80upx;
				height: 40upx;
				background: inherit;
				background-color: rgba(241, 151, 54, 1);
				border-width: 1upx soild rgba(241, 151, 54, 1);
				border-radius: 42upx;
				border-bottom-left-radius: 0upx;
				-moz-box-shadow: none;
				-webkit-box-shadow: none;
				font-family: '微软雅黑';
				font-weight: 404;
				font-size: 24upx;
				color: #FFFFFF;
				text-align: center;
				/* line-height: 25upx */
			}
			
		}
		.more{
			display:flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			flex-shrink: 0;
			width: 180upx;
			height: 180upx;
			border-radius: 6upx;
			background: #f3f3f3;
			font-size: $font-base;
			color: $font-color-light;
			text:first-child{
				margin-bottom: 4upx;
			}
		}
	}
	.navbar{
		border-top: 1upx solid #888;
		margin-top: -2upx;
		display: flex;
		position:fixed;
		height: 40px;
		width: 750upx;
		background: #fff;
		/* position: relative; */
		z-index: 10;
		.nav-item{
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: $font-color-dark;
			position: relative;
			&.current{
				color: $base-color;
				&:after{
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}
	.all{
		background-color: #f5f5f5;
		margin-top: 80upx;
	}
	.top{
		background-color: #fff;
		margin-bottom: 20upx;
		.button{
			width: 90%;
			background-color: #E02E24;
		}
		.texts{
			text-align: center;
			font-size: 25upx;
			color: #ccc;
			padding-top: 20upx;
			.text{
				padding-top: 20upx;
			}
		}
	}
	.buttom{
		margin-bottom: -90upx;
		background-color: #fff;
		margin-top: 30upx;
		padding: 0upx 40upx;
		font-size: 25upx;
		color: 	#808080;
		.top{
			font-size: 30upx;
			text-align: center;
			padding: 40upx 0upx;
		}
		.mid{
			margin: 50upx 0upx;
			.tittle{
				font-weight: 800;
				margin-bottom: 10upx;
			}
			.text{
				display: flex;
			}
		}
		.text{
			line-height: 40upx;
		}
	}
</style>
